/**************************************************************************************** 
 Copyright © 2003-2012 ZTEsoft Corporation. All rights reserved. Reproduction or       <br>
 transmission in whole or in part, in any form or by any means, electronic, mechanical <br>
 or otherwise, is prohibited without the prior written consent of the copyright owner. <br>
 ****************************************************************************************/
package com.iwhalecloud.bss.kite.cucc.service.addRoleProdDeal;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import javax.annotation.PostConstruct;

import org.springframework.aop.support.AopUtils;
import org.springframework.stereotype.Component;

import com.iwhalecloud.bss.kite.common.util.KiteMapUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.ztesoft.bss.common.util.SpringUtil;

/** 
 * <Description> <br> 
 *  
 * @author tengg<br>
 * @version 1.0<br>
 * @taskId <br>
 * @CreateDate 2021年3月27日 <br>
 * @since R9.0<br>
 * @see com.iwhalecloud.bss.kite.cucc.service.addRoleProdDeal <br>
 */
@Component
public class AddRoleProdFactory {
    private static Map<String,  IAddRoleProdService> addRoleSuppliers = new HashMap<>();

    @PostConstruct
    public void init() {
        Map<String, ? extends IAddRoleProdService> addRoleProdServiceMap = SpringUtil.getApplicationContext()
            .getBeansOfType(IAddRoleProdService.class);
        if (KiteMapUtils.isNotEmpty(addRoleProdServiceMap)) {
            addRoleProdServiceMap.forEach((s, o) -> {
                AddRoleProd[] addRoleProds = AopUtils.getTargetClass(o).getAnnotationsByType(AddRoleProd.class);
                if (Objects.nonNull(addRoleProds)) {
                    for (AddRoleProd h : addRoleProds) {
                        String[] addRoleTypes = h.value();
                        for (String value : addRoleTypes) {
                            addRoleSuppliers.put(value, o);
                        }
                    }
                }
            });
        }
    }
    
    public static IAddRoleProdService getRoleProdSupplier(String catId)  {
        if (KiteStringUtils.isEmpty(catId)) {
            return null;
        }
        IAddRoleProdService bean = addRoleSuppliers.get(catId);
        if (Objects.isNull(bean)) {
            return null;
        }
        return bean;
    }
}
